package com.example.personalizededucationsystem.dto.response;

import com.example.personalizededucationsystem.model.KnowledgePoint;
import com.example.personalizededucationsystem.model.Question;
import lombok.Getter;
import lombok.Setter;

import java.util.Set;
import java.util.stream.Collectors;

@Setter
@Getter
public class QuestionResponse {
    private Long questionId;
    private String content;
    private Question.QuestionType type;
    private String options;
    private Float difficulty;
    private Set<String> knowledgePoints;

    // 一个静态工厂方法，方便地从实体转换到DTO
    public static QuestionResponse fromEntity(Question question) {
        QuestionResponse dto = new QuestionResponse();
        dto.setQuestionId(question.getQuestionId());
        dto.setContent(question.getContent());
        dto.setType(question.getType());
        dto.setOptions(question.getOptions());
        dto.setDifficulty(question.getDifficulty());
        if (question.getKnowledgePoints() != null) {
            dto.setKnowledgePoints(question.getKnowledgePoints().stream()
                    .map(KnowledgePoint::getName)
                    .collect(Collectors.toSet()));
        }
        return dto;
    }

}